package br.ucb.sacop.dao;

import java.sql.SQLException;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import br.ucb.sacop.bean.Aluno;
import br.ucb.sacop.bean.Login;

import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;

public class DatabaseHelper extends OrmLiteSqliteOpenHelper{
	private static final String databaseName = "sacop";
	private static final int databaseVersion = 1;
	
	
	public DatabaseHelper(Context context) {
		super(context, databaseName, null, databaseVersion);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void onCreate(SQLiteDatabase sd, ConnectionSource cs) {
		try {
			TableUtils.createTable(cs, Aluno.class);
			TableUtils.createTable(cs, Login.class);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}

	@Override
	public void onUpgrade(SQLiteDatabase sd, ConnectionSource cs, int oldVersion,
			int newVersion) {
		try {
			TableUtils.dropTable(cs, Aluno.class, true);
			TableUtils.dropTable(cs, Login.class, true);
			onCreate(sd, cs);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
	}
	
	@Override
	public void close(){
		super.close();
	}

}
